package com.example.microinvestweb.controller.user;
import com.example.microinvestcommon.pojo.Result;
import com.example.microinvestuser.service.user.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


//此Controller用于处理用户登录登出以及查找用户
@RestController
@RequestMapping("/auth")
public class AuthController {

    private final AuthService authService;

    @Autowired
    public AuthController(AuthService authService){
        this.authService=authService;
    }


    //登录模式1：用户名加密码形式
    @PostMapping("/loginWithUsernamePassword")
    public Result<String> loginWithUsernamePassword(String userName,String password){
        //由前端判断输入是否为空
        Result result=authService.loginWithUsernamePasswordService(userName,password);
        return result;
    }

    //登录模式2：邮箱验证码登录
    //邮箱登录第一步，发送邮件且存入验证码存入Redis
    @PostMapping("/loginWithEmailStepOne")
    public Result<String> loginWithEmailStepOne(String email){
        //由前端判断输入是否为空
        Result result=authService.sendEmailService(email);
        return result;
    }

    //邮箱登录第二部，验证用户的验证码是否正确，正确则允许登录
    @PostMapping("/loginWithEmailStepTwo")
    public Result<String> loginWithEmailStepTwo(String email,String code){
        //由前端判断验证码是否输入为空
        Result result=authService.verificationLoginCodeService(email,code);
        return result;
        }

    }


